package ap1213.ga2.rocco;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.GregorianCalendar;

public class AP1213HS3b {
	
	public static File input = new File("src/ap1213/rocco/ga2/Ein_Bilder");
	public static void main(String[] args) {
		bildSuchen(
		// cam nr
				1
				// date
				, new GregorianCalendar(2012, 10, 30)
				// hours
				, 23
				// minutes
				, 58);
	}
	private static void bildSuchen(int camnr, GregorianCalendar date, int hour,
			int min) {
		BufferedReader br = null;
		BufferedWriter bw = null;
		try {
			bw = new BufferedWriter(new FileWriter(new File("src/ap1213/rocco/ga2/ergebnis")));
			br = new BufferedReader(new FileReader(input));
			String line = "";
			while ((line = br.readLine()) != null) {

				//same camnr?
				if (Integer.valueOf(line.substring(0, 3)) == (camnr)) {
					GregorianCalendar gc = new GregorianCalendar(
							//Year
							Integer.valueOf(line.substring(4, 8)),
							//Month
							Integer.valueOf(line.substring(9, 11)),
							//day
							Integer.valueOf(line.substring(12, 14)));
					//same date?
					if (gc.equals(date)) {
						//same hour?
						if (Integer.valueOf(line.substring(15, 17)) == hour) {
							//same minute?
							if (Integer.valueOf(line.substring(18, 20)) == min) {
								System.out.println(line);
								bw.write(line + "\n");
							}
						}
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
				bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}